import 'package:aihu_getx_app/app/modules/commons/commons.dart';
import 'package:aihu_getx_app/app/routes/app_pages.dart';
import 'package:aihu_getx_app/config/app_init_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class Application extends StatelessWidget {
  final AppInitData initData;

  const Application({super.key, required this.initData});

  @override
  Widget build(BuildContext context) {
    final easyLoad = EasyLoading.init();
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: "云享嘉",
      theme: initData.theme,
      initialRoute: Commons.getLastSplashPage(),
      unknownRoute: AppPages.routes.firstWhere(
        (element) => element.name == Routes.notFound,
      ),
      getPages: AppPages.routes,
      defaultTransition: Transition.fade,
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      locale: const Locale('zh', 'CH'),
      supportedLocales: const [
        Locale('zh', 'CH'),
        Locale('en', 'US'),
      ],
      builder: (BuildContext context, Widget? child) {
        ScreenUtil.init(context);
        child = easyLoad(context, child);
        return child;
      },
    );
  }
}
